import Vue from 'vue'
import VueRouter from 'vue-router'
import System from '../views/System/System.vue'
import LogsList from '../components/logs/LogsList.vue'
import MakeParkings from '../components/manger/MakeParkings.vue'
import MakeLessors from '../components/manger/MakeLessors.vue'
import MakeOrders from '../components/manger/MakeOrders.vue'
import MakeTenants from '../components/manger/MakeTenants.vue'

import EditLessors from '../components/manger/EditLessors.vue'
import EditParkings from '../components/manger/EditParkings.vue'
import EditTenants from '../components/manger/EditTenants.vue'

import Register from '../views/Register/Register.vue'
import Login from '../views/Login/Login.vue'
import apis from '../http/apis/apis.js';
// 个人项目
import TenantsSystem from '../components/tenants/TenantsSystem.vue'
import Home from '../components/tenants/Home.vue'


Vue.use(VueRouter)

const routes = [
    // 个人项目-ml
    {
        path: '/TenantsSystem/',
        name: 'TenantsSystem',//路由名，可以不写
        // props: true,
        //当浏览器中的地址与当前路由的path匹配成功时，对应页面要加载的组件
        component: TenantsSystem,
        children: [
            {
                path: "home",
                name: "Home",
                component: Home
            },
        ]
    },
    // 登录
    {
        path: '/login',//路由的路径
        name: 'Login',//路由名，可以不写
        // props: true,
        //当浏览器中的地址与当前路由的path匹配成功时，对应页面要加载的组件
        component: Login
    },
    /**********练超开始************/
    //出租方注册
    {
        path: '/register',
        name: 'Register',
        component: Register
    },
    /**********练超结尾************/

    //获取停车位列表  廖冬
    {
        path: '/system/',
        name: 'System',
        component: System,
        // 导航守卫
        beforeEnter: async (to, from, next) => {
            const { data } = await apis.login.isLogin();
            if (data.type == 401) {
                alert('你还未登录，请先登录');
                console.log(data);
                next('/login')
            } else {
                next()
            }
        },
        children: [
            //管理员租客，出租方，车位黄涛
            {
                path: "makelessors",
                name: "MakeLessors",
                component: MakeLessors
            },
            {
                path: "maketenants",
                name: "MakeTenants",
                component: MakeTenants
            },
            {
                path: "makeorders",
                name: "MakeOrders",
                component: MakeOrders
            },
            {
                path: "makeparkings",
                name: "MakeParkings",
                component: MakeParkings
            },
            //管理员对租客，出租方，车位的编辑部分   黃涛
            {
                path: "editlessors/:id",
                name: "EditLessors",
                props: true,
                component: EditLessors
            },
            {
                path: "editparkings/:id",
                name: "EditParkings",
                props: true,
                component: EditParkings
            }, {
                path: "edittenants/:id",
                name: "EditTenants",
                props: true,
                component: EditTenants
            },


            //添加车位 冰
            {
                path: 'addparking',
                name: 'AddParking',
                component: () => import('../components/lessors/AddParking.vue'),
                meta: {
                    keepAlive: true
                }
            },

            //获取停车位列表  廖冬
            {
                path: 'ParkingList',
                name: 'ParkingList',
                component: () => import('../components/lessors/ParkingList'),
            },
            {
                path: 'historyOrders',
                name: 'historyOrders',
                component: () => import('../components/lessors/HistoryOrders')
            },
            //查看已租出车辆的订单 冰
            {
                path: 'myorders',
                name: 'MyOrders',
                component: () => import('../components/lessors/MyOrders.vue'),
            },

            //查看车位租赁订单 冰
            {
                path: 'renttenants/:_id',
                name: 'RentTenants',
                props: true,
                component: () => import('../components/lessors/RentTenants.vue'),
            },
            /**********练超开始************/
            //普通管理员，管理
            {
                path: 'adminsSystem',
                name: 'adminsSystem',
                component: () => import('../components/admins/AdminsSystem.vue'),
            },
            //新增普通管理员
            {
                path: 'addAdmins',
                name: 'addAdmins',
                component: () => import('../components/admins/AddAdmin.vue'),
            },
            //修改普通管理员
            {
                path: 'modifyAdmins/:_id',
                name: 'modifyAdmins',
                component: () => import('../components/admins/ModifyAdmin.vue'),
            },
            //查找普通管理员
            {
                path: 'seekAdmins/',
                name: 'seekAdmins',
                component: () => import('../components/admins/SeekAdmins.vue'),
            },
            /**********练超结尾************/
            // 登录日志
            {
                path: 'logslist',
                name: 'LogsList',
                component: LogsList
            }
        ]
    },
]




const router = new VueRouter({
    routes,
})

export default router